#!/bin/sh

# 文件名
orgCode="$1"
imageTag="$2"

# 获取端口号
while read line;do
    eval "$line"
done < latest-port.txt

orgPort=$port
newOrgPort=`expr ${orgPort} + 1`

# 生成新端口号
sed -e "s#servicePort#${newOrgPort}#g" latest-port.tpl > latest-port.txt

# 生成服务安装文件
tee /home/install/${orgCode}.yml <<- EOF
version: "3"
services:
  s${orgCode}:
    # 重启后自动打开
    environment:
      - TZ=Asia/Shanghai
    image: 10.15.3.32:1801/ssm-docker-swarm/grass-roots-mini-app-h5:${imageTag}
    ports:
      - "${orgPort}:5644"
EOF

# 服务安装
docker stack deploy -c ${orgCode}.yml service01